
// import TableList from "@components/templates/tablelist";
import TableList from "@components/templates/customtablelist";
import { HttpAccount, HttpAccountTotal } from '@/service/api/views'
import { mapState,mapGetters } from "vuex";
// import compAdd from './add';
export default {
    mixins: [TableList],
    components: {
        // compAdd,
    },
    data() {
        return {
            // totals: 0,
            isMixin: true,
            Tools: {show: true},
            Tabs: {show: true},
            formData:{
                search:{
                }
            },
            Searchs: {
                show: true,
                labelWidth: 120,
            },
            Plugins: {show: true},
            btnsearch: [
                {
                    text: '本月',
                    value() {
                        const date = new Date();
                        date.setDate(1);
                        date.setHours(0, 0, 0);
                        return [date, new Date()];
                    }
                },
                {
                    text: '上月',
                    value() {
                        let now = new Date(),
                            end = new Date(Date.parse(`${now.getFullYear()}-${now.getMonth() + 1}-01 00:00:00`) - 360000);
                        return [new Date(`${end.getFullYear()}-${end.getMonth() + 1}-01 00:00:00`), end];
                    }
                },
                {
                    text: '本季度',
                    value() {
                        return handleTime('cur')
                    }
                },
                {
                    text: '上季度',
                    value() {
                        return handleTime('pre');
                    }
                }
            ],
            totalnum:'',
        }
    },
    methods: {
        ajaxRequest: HttpAccount,
        interceptRequest(params){
            if(params.search.BT_createdAt&&params.search.BT_createdAt[0]!=''){
                params.search.BT_createdAt = this.handleDateFormat(params.search.BT_createdAt[0],'yyyy-mm-dd') + ' ~ ' +this.handleDateFormat(params.search.BT_createdAt[1],'yyyy-mm-dd')
            }
            switch(params.search.EQ_time){
                case '1':
                    const date = new Date();
                        date.setDate(1);
                        date.setHours(0, 0, 0);
                        params.search.BT_createdAt = this.handleDateFormat(date) + ' ~ ' +this.handleDateFormat(new Date());
                break;
                case '2':
                    const  date2 = new Date(),
                           end = new Date(Date.parse(`${date2.getFullYear()}-${date2.getMonth() + 1}-01 00:00:00`) - 360000);
                    
                        params.search.BT_createdAt = this.handleDateFormat(new Date(`${end.getFullYear()}-${end.getMonth() + 1}-01 00:00:00`)) + ' ~ ' +this.handleDateFormat(end)
                break;
                case '3':
                    params.search.BT_createdAt = this.handleDateFormat(this.handleTime('cur')[0]) + ' ~ ' +this.handleDateFormat(this.handleTime('cur')[1])
                break;
                case '4':
                    params.search.BT_createdAt = this.handleDateFormat(this.handleTime('pre')[0]) + ' ~ ' +this.handleDateFormat(this.handleTime('pre')[1])
                break;
            }
            delete params.search.EQ_time;
            HttpAccountTotal({...params}).then(res=>{
                this.totalnum = res.data
            })
            return params
        },
        toolsRender() { //自定义工具行
            return (
                <div style="background: #fff;margin-bottom: 10px;padding: 5px;padding-left: 10px;">
                    <span class="color-success">总收入:{this.totalnum.totalRevenue}</span>
                    <span class="color-error margin-left-20">总支出:{this.totalnum.totalExpenses}</span>
                </div>
            ) 
        },
        handleOperates(params="", type,batch) {
            if(batch===true){
                params=(params||this.checkedData.join(','))+'';
                if(!params.length) return this.$Message.warning('请选择至少一条数据');
            }
            switch (type) {
                case 'download':
                    this.handleWebfs(
                        process.env.VUE_APP_APIURL_SHIP + "/api/jwt/spl/transactionrecord/export",{},
                        "download"
                    );
                    break;
                
            }
        },
        handleTime(type){
            let date = new Date();
            let month = date.getMonth() + 1,
                year = date.getFullYear(),
                start, end;
            month = Math.ceil(month / 3) * 3 - 2;
            if (type === 'pre') {
                month -= 3;
            }
            if (month < 1) {
                year -= 1;
                start = new Date(`${year}-10-01 00:00:00`);
                end = new Date(`${year}-12-31 23:59:59`);
            } else {
                start = new Date(`${year}-${month}-01 00:00:00`);
                end = new Date(year, month + 2, 0);
            }
            return [start, end];
        },
    },
    computed: {
        ...mapGetters('diction',['getNewDifferentAllProductList','getNewAccountList']),
        TabsData(){
            return [
                {
                    name: this.$ct('global.common.all',{defaultValue:'全部'}),
                    key:'EQ_time',
                    val: null
                }, {
                    name: '本月',
                    key:'EQ_time',
                    val: "1"
                }, {
                    name: '上月',
                    key:'EQ_time',
                    val: "2"
                }, {
                    name: '本季度',
                    key: "EQ_time",
                    val:"3"
                }, {
                    name: '上季度',
                    key: "EQ_time",
                    val:"4"
                }
            ]
        },
        // 搜索下拉框展示内容
        SearchsData() {
            return  [
                {
                    label: '类型',
                    tag: 'Select',
                    key: 'EQ_type',
                    options:[
                        {value:0,label:'收入'},
                        {value:1,label:'支出'},
                    ],
                    show:true,
                },

                {
                    label: '二级分类',
                    tag: 'Select',
                    key: 'EQ_category',
                    options:[
                        {value:0,label:'充值'},
                        {value:1,label:'扣费'},
                        {value:4,label:'退款'},
                    ],
                    show:true,
                },
                {
                    label: '单号',
                    tag: 'Input',
                    key: 'EQ_trackingNo',
                    show:true,
                },
                {
                    label: '交易时间',
                    tag: 'DatePicker',
                    key: 'BT_createdAt',
                    props:{
                        options:this.options,
                        type:'daterange',
                    },
                    // hideSearchTip:true,
                    style: "width:200px",
                },
            ]
        },
        ToolsData(){
            return [
                {
                    name: "导出",
                    theme: 'success',
                    operate: 'download',
                },
            ]
        },
        // table的展示数据
        columns() {
            return [{
                title: "交易时间",
                key: "createdAt",
                sortable: true,
            }, {
                title: "类型",
                key: "type",
                sortable: true,
                render(h, { row }) {
                    return <span>{row.type == 0 ? '收入' : '支出'}</span>
                }
            },{
                title: "二级分类",
                key: "category",
                width:100,
                sortable: true,
                render(h, { row }) {
                    switch (row.category) {
						case 0: return <Tag type="border" color="primary" size='small'>充值</Tag>; break;
						case 1: return <Tag type="border" color='error' size='small'>扣费</Tag>; break;
						case 2: return <Tag type="border" color='warning' size='small'>冻结</Tag>; break;
						case 3: return <Tag type="border" color='success' size='small'>解冻</Tag>; break;
						case 4: return <Tag type="border" color='purple' size='small'>退款</Tag>; break;
					}
                }
            },{
                title: "描述",
                key: "remark",
                maxWidth: 200,
            }, {
                title: "交易金额(USD)",
                key: "amount",
                sortable: true,
            }, {
                title: "账户余额",
                key: "availableAmount",
                sortable: true,
            }, {
                title: "单号",
                key: "trackingNo",
            },];
        },
        
    },

};
